<?php
/*
$JA#COPYRIGHT$
*/


defined('_JEXEC') or die('Retricted Access');
if (! class_exists ( 'JAStack' )&&! class_exists ( 'SmartTrim' ))
	require_once(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'helper'.DS.'jahelper.php');
global $jbconfig, $option;  

$modID = "JAJobsMap".$module->id;

$centerLocation = getLocation( $params->get("center_location", "0") );

?>

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo $params->get("api_key", "");?>&sensor=true"
 type="text/javascript"></script>
<script type="text/javascript">
// initialize map
function initializeJAJobsMap(MapID) {
  if (GBrowserIsCompatible()) {
    
    // Initialize
    var map = new GMap2(document.getElementById(MapID));   
    var info = "";
    
    // Set map Center    
    var geocoder = new GClientGeocoder();
    geocoder.getLatLng( "<?php echo $centerLocation;?>", function (point) {
				if (!point) {
					alert(address + " not found");
				} else {					
					map.setCenter( point , <?php echo $params->get("zoom_level", "5");?>);
					
					<?php
					if( is_array($this->all_items) ){
						
						$Itemid = get_Itemid(array('option'=>'com_jajobboard', 'view'=>'jajobs', 'layout'=>'jaview'));
					    
						foreach ($this->all_items as $item){
					        $jobLocation = $item->{$field_name};
					        $alias = JFilterOutput::stringURLSafe(trim($item->title));
					        ?>					        
					        geocoder.getLatLng( "<?php echo $jobLocation;?>", function (points) { 
					            info = "<div style='text-align:left; padding: 5px'><strong><a href='<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&layout=jaview&cid[]='.$item->id.'&alias='.$alias."&Itemid=".$Itemid); ?>'><?php echo $item->title?></a></strong> <br/>"
					                   + "<?php echo JText::_("Location");?>: <?php echo $item->location_id?></div>";
					            var marker = new GMarker(points, {title: "<?php echo JText::_("Click to view job info: ").$item->title;?>"});
            					marker.bindInfoWindow( info );										
            					map.addOverlay(marker);
					        });					        
        					
					        <?php
					    } 
					}					
					?>
				}
			});
    
    // Default theme   
    map.setUIToDefault();
  }
}

// Load map when page loaded
window.addEvent('domready', function() {
    initializeJAJobsMap("<?php echo $modID;?>");
});

window.addEvent('onunload', function() {
    GUnload();
});

</script>

<div class="jobs_map_region">
    <div style="width: <?php echo $params->get("map_width", "100%");?>; height: <?php echo $params->get("map_height", "500px");?>" 
    class="jobs_map_region_map" 
    id="<?php echo $modID;?>"></div>
</div>